import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: Login
    },
    {
      path: '/',
      component: Layout,
      children: [
        {
          // 默认路由
          path: '',
          component: () => import('@/views/Home/index.vue')
        },
        {
          path: '/category/:id',
          component: () => import('@/views/Category/index.vue')
        },
        {
          path: '/category/sub/:id',
          component: () => import('@/views/SubCategory/index.vue')
        },
        {
          path: '/detail/:id',
          component: () => import('@/views/Detail/index.vue')
        },
        {
          path: '/cartlist',
          component: () => import('@/views/CartList/index.vue')
        },
        {
          path: '/checkout',
          component: () => import('@/views/CheckOut/index.vue')
        },
        {
          path: '/pay',
          component: () => import('@/views/Pay/index.vue')
        },
        {
          path: '/payback',
          component: () => import('@/views/Pay/PayBack.vue')
        },
        {
          path: '/member',
          component: () => import('@/views/Member/index.vue'),
          redirect: '/member/user',
          children:[
            {
              path: 'user',
              component: () => import('@/views/Member/components/UserInfo.vue'),
            },
            {
              path: 'order',
              component: () => import('@/views/Member/components/UserOrder.vue'),
            },
          ]
        }
      ]
    },
  ],
  // 路由行为
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
